package com.lhb.order.controller;

import com.lhb.common.model.UnifyResponseObject;
import com.lhb.order.model.Order;
import com.lhb.order.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.List;

/**
 * @author 86131
 * @version 1.0
 * @description
 * @date 2025/8/12 下午5:02
 */
@RestController
@RequestMapping("/order")
public class OrderController {

    @Autowired
    OrderService orderService;

    @PostMapping("/addOrder")
    public UnifyResponseObject addOrder(@RequestBody Order order)
    {
        orderService.addOrder(order);

        return UnifyResponseObject.success("");

    }

    @GetMapping("/getAllOrder")
    public UnifyResponseObject<List<Order>> getAllOrder()
    {
       List<Order>  orderList= orderService.getAllOrder();

       return UnifyResponseObject.success(orderList,"");
    }

    @GetMapping("/getUnpaid")
    public UnifyResponseObject<List<Order>> getUnpaid()
    {
        List<Order>  orderList= orderService.getUnpaid();
        return UnifyResponseObject.success(orderList,"");
    }


    @GetMapping("/getPaid")
    public UnifyResponseObject<List<Order>> getPaid()
    {
        List<Order>orderList= orderService.getPaid();
        return UnifyResponseObject.success(orderList,"");
    }

    @DeleteMapping("/deleteOrder/{id}")
    public UnifyResponseObject deleteOrder(@PathVariable("id") Long id)
    {
        orderService.deleteOrder(id);
        return UnifyResponseObject.success("删除成功");
    }

    @PutMapping("/modifyOrder/{id}")
    public UnifyResponseObject modifyOrder(@PathVariable("id") Long id,@RequestParam("flightId") Long flightId) throws IOException {
        orderService.modifyOrder(id,flightId);
        return UnifyResponseObject.success("支付成功");
    }




}
